using UnityEngine;
using System.Collections;

public class MainScript : MonoBehaviour {
	
	private Rect windowRect = new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 50, 25);
	
	void OnGUI()
	{
		
		GUILayout.BeginArea (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
		GUILayout.BeginVertical();

		
		if (GUILayout.Button("Start Game"))
		{
			Application.LoadLevel("Game");
			//gameObject.AddComponent<CreditScript>();
			
					bool win = false;
		//windowRect = GUI.Window (0, windowRect, WindowFunction, "");
		GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100), "YAY! This is the game! YAY!");
		
		if(Input.GetKeyUp(KeyCode.Escape)&&win==false)
			{
				win = true;
			}
			if(Input.GetKeyUp(KeyCode.Escape)&&  win==true)
			{
				win = false;	
			}
		
		if (win == true) 
		{
			GUILayout.BeginArea (windowRect = GUI.Window (0, windowRect, WindowFunction, ""));
			
			GUILayout.Label("Are you sure you want to quit?");
			GUILayout.BeginHorizontal();
			
			if(GUILayout.Button ("Yes"))
			{
				Application.LoadLevel("Main");
			}
			
			if(GUILayout.Button ("No"))
			{
				win = false;
			}
			
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
		}
		}
		if(GUILayout.Button ("Credits"))
		{
			Application.LoadLevel ("Credits");
			gameObject.AddComponent<CreditScript>();
		}
			

		if (GUILayout.Button ("Quit"))
		{
			Application.Quit ();
		}


		GUILayout.EndVertical();
		GUILayout.EndArea();
	}
	
			void WindowFunction (int windowID) {
		// Draw any Controls inside the window here
	}
	
}
